import React, { Component } from 'react';

class OneRef extends Component {

    //获取数据
    getValue = () => {
        //获取输入框的值
        let value = this.refs.input.value;
        // console.dir(this.refs.input.value);
        //获取div 真实dom对象并 赋值
        // console.dir(this.refs.box);
        this.refs.box.innerHTML = value;

        //清空输入框
        this.refs.input.value = "";
    }

    render() {
        return (
            <>
                <h1>字符串形式的ref</h1>
                <input ref="input" type="text" />
                <button onClick={this.getValue}>获取数据并展示</button>
                <div ref="box" style={{width:300,height:300,border:"1px solid red"}}></div>
            </>
        );
    }
}

export default OneRef;